package brickdestroyer.simulation;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import static brickdestroyer.simulation.Simulation.*;

/**
 * This class manages all the help information in the game.
 * 
 * @author Momchil
 */
public class HelpManager {
    
    private static final String[] HELP_LINES =
    {"                    Game Paused",
     "",
     "Here is all you need to know to play the game:",
     "  * Pressing 'F2' restarts the game.",
     "  * You must click 'Right Mouse Button' to start",
     "    the level.",
     "  * The slider is controlled via the mouse.",
     "  * Clicking 'Left Mouse Button' changes the mode",
     "    of the slider.",
     "  * When the slider is in 'active' (red) mode it adds",
     "    additional vertical speed to the ball on collision.",
     "  * When a ball hits the slider in a position different",
     "    than the center, additional side speed is added.",
     "  * Pressing 'ALT+F4' will close the game.",
     "  * To hide the help press 'Escape' again.",
     "",
     "  Thank you for playing the game and have fun!"};

    /*
     * X coordinate of the help lines on the screen.
     */
    private static final int HELP_LINES_X = 90;

    /*
     * Y coordinate of the help lines on the screen.
     */
    private static final int HELP_LINES_Y = 30;

    /*
     * Distance between each line and the next.
     */
    private static final int HELP_LINES_SEPARATION = 20;
    
    private boolean visible = false;

    private final Font CHARACTER_FONT = new Font(Font.DIALOG_INPUT, Font.BOLD, 14);
    
    public HelpManager() {
    }

    /**
     * This toggles the visibility of the help manager.
     * @return <code>true</code> if the help manager is visible
     * after the change, <code>false</code> otherwise.
     */
    public boolean toggle() {
        visible = !visible;
        return visible;
    }

    /**
     * This method checks if the manager is visible or not.
     * @return <code>true</code> if the manager is visible,
     * <code>false</code> otherwise.
     */
    public boolean isVisible() {
        return visible;
    }

    /**
     * This method displays the help manager on the screen.
     * @param g interface to the graphics handle.
     */
    public void display(Graphics2D g) {
        if (!visible) {
            return;
        }
        
        g.setColor(new Color(0xCC000000, true));
        g.fillRect(0, 0, PLAYABLE_AREA_WIDTH, PLAYABLE_AREA_HEIGHT);

        g.setColor(Color.WHITE);
        g.setFont(CHARACTER_FONT);
        int lineX = HELP_LINES_X;
        int lineY = HELP_LINES_Y;
        for (String line : HELP_LINES) {
            g.drawString(line, lineX, lineY);
            lineY += HELP_LINES_SEPARATION;
        }
    }

}
